package com.fqgj.sentry.controller.pc;

import com.fqgj.sentry.biz.pc.EventBusiness;
import com.fqgj.sentry.biz.pc.vo.event.EventVo;
import com.fqgj.sentry.common.cache.RequestLocalInfo;
import com.fqgj.sentry.common.response.ApiOutput;
import com.fqgj.sentry.common.utils.ApiPage;
import com.fqgj.sentry.controller.pc.request.AddEventVo;
import com.fqgj.sentry.controller.pc.request.EventPageVo;
import com.fqgj.sentry.controller.pc.request.UpdateEventVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by zwh @yuntu-inc.com
 *
 * @description
 * @create 2017/7/26 0026 下午 8:30
 */
@RestController
@RequestMapping(value = "/event")
public class EventController {
    @Autowired
    private EventBusiness eventBusiness;

    /**
     * 事件新增
     *
     * @param addEventVo
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ApiOutput saveEvent(@RequestBody AddEventVo addEventVo) {
        eventBusiness.saveEvent(RequestLocalInfo.getCurrentMerchantId(), addEventVo);
        return new ApiOutput<>();
    }

    /**
     * 事件删除
     *
     * @param eventId
     * @return
     */
    @RequestMapping(value = "/{eventId}/delete", method = RequestMethod.POST)
    public ApiOutput deleteEvent(@PathVariable Long eventId) {
        eventBusiness.deleteEvent(eventId);
        return new ApiOutput<>();
    }

    /**
     * 事件更新
     *
     * @param updateEventVo
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ApiOutput updateEvent(@RequestBody UpdateEventVo updateEventVo) {
        eventBusiness.updateEvent(updateEventVo);
        return new ApiOutput<>();
    }

    /**
     * 查询事件列表
     *
     * @param eventPageVo
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiOutput listEvent(@RequestBody EventPageVo eventPageVo) {
        ApiPage apiPage = eventBusiness.listEvent(RequestLocalInfo.getCurrentMerchantId(), eventPageVo);
        return new ApiOutput<>(apiPage);
    }

    /**
     * 查询事件列表
     */
    @RequestMapping(value = "/combo", method = RequestMethod.POST)
    public ApiOutput comboEvent() {
        List<EventVo> eventVoList = eventBusiness.comboEvent(RequestLocalInfo.getCurrentMerchantId());
        return new ApiOutput<>("list", eventVoList);
    }


}
